package rx;

import android.support.annotation.NonNull;
import io.reactivex.Observable;
import io.reactivex.ObservableEmitter;
import io.reactivex.Observer;
import io.reactivex.disposables.Disposable;

/**
 * Created by wangxingsheng on 2019/3/21.
 */
public class RxExTest {

    public static Observable<String> rxTest(@NonNull String key) {
        return Observable.create((ObservableEmitter<String> s) -> {
            s.onNext(key + new OBJ().name.toLowerCase());
            s.onComplete();
        });
    }

    public static void main(String[] args) {
        rxTest("test1")
                .subscribe(new Observer<String>() {
                    @Override
                    public void onSubscribe(Disposable d) {

                    }

                    @Override
                    public void onNext(String s) {
                        System.out.println(s);
                    }

                    @Override
                    public void onError(Throwable e) {
                        System.out.println(e.toString());
                    }

                    @Override
                    public void onComplete() {

                    }
                });
//        RxJavaPlugins.setErrorHandler(throwable -> System.out.println(throwable.getCause()));
        rxTest("test3").subscribe(System.out::print);
    }

    static class OBJ {
        public String name;
    }
}
